package client.setup.gui;

import client.setup.IdentifierRetriver;
import java.io.File;
import java.text.DecimalFormat;
import java.io.IOException;
import java.util.ResourceBundle;
import java.util.concurrent.ExecutionException;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import client.Configuration;
import communication.BandwidthConnection;
import utils.EmailUtils;
import constans.ConfigurationConstans;
import constans.SizeConstans;
import java.awt.Cursor;
import java.net.URISyntaxException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.border.TitledBorder;
import utils.MachineUtils;
import utils.ScreenUtils;


public class SetupFrame extends javax.swing.JFrame {

	private ResourceBundle rb;
    private Logger logger;
	private IdentifierRetriver identifierRetriver;
	private DecimalFormat df;
	private boolean result;
        


	public SetupFrame(ResourceBundle rb,Logger logger) {
        initAttributes(rb,logger);
		initComponents();                 
		ScreenUtils.setMiddleScreen(this);
		setVisiblePanels(true,false,false,false,false,false);
		setVisibleButtons(true,false,true);
    }
    
	@SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        welcomePanel = new javax.swing.JPanel();
        wLabel_1 = new javax.swing.JLabel();
        wLabel_2 = new javax.swing.JLabel();
        wLabel_3 = new javax.swing.JLabel();
        locationPanel = new javax.swing.JPanel();
        uLabel6 = new javax.swing.JLabel();
        uLabel10 = new javax.swing.JLabel();
        uLabel11 = new javax.swing.JLabel();
        jTextField6 = new javax.swing.JTextField(4) ;
        jTextField7 = new javax.swing.JTextField(40) ;
        uLabel12 = new javax.swing.JLabel();
        uLabel13 = new javax.swing.JLabel();
        uLabel14 = new javax.swing.JLabel();
        uLabel15 = new javax.swing.JLabel();
        jTextField5 = new javax.swing.JTextField(3);
        jLabel10 = new javax.swing.JLabel();
        userPanel = new javax.swing.JPanel();
        uLabel1 = new javax.swing.JLabel();
        jRadioButton1 = new javax.swing.JRadioButton();
        jRadioButton2 = new javax.swing.JRadioButton();
        uLabel2 = new javax.swing.JLabel();
        uLabel3 = new javax.swing.JLabel();
        uLabel4 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField(50);
        jTextField2 = new javax.swing.JPasswordField(10);
        jTextField3 = new javax.swing.JPasswordField(10);
        uLabel5 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jTextField4 = new javax.swing.JTextField();
        uLabel9 = new javax.swing.JLabel();
        configurationPanel = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jComboBox1 = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jSlider1 = new javax.swing.JSlider();
        jLabel3 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        setupPanel = new javax.swing.JPanel();
        sLabel_1 = new javax.swing.JLabel();
        sProgressBar_1 = new javax.swing.JProgressBar();
        sLabel_2 = new javax.swing.JLabel();
        finishPanel = new javax.swing.JPanel();
        fLabel_1 = new javax.swing.JLabel();
        fLabel_2 = new javax.swing.JLabel();
        fLabel_3 = new javax.swing.JLabel();
        fLabel_4 = new javax.swing.JLabel();
        button_next = new javax.swing.JButton();
        button_back = new javax.swing.JButton();
        button_cancel = new javax.swing.JButton();
        separator = new javax.swing.JSeparator();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle(rb.getString("SetupMainTitle"));
        setIconImage(new ImageIcon(SetupFrame.class.getResource("/client/setup/images/awp_16x16.png")).getImage());
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        mainPanel.setPreferredSize(new java.awt.Dimension(611, 363));

        wLabel_1.setFont(new java.awt.Font("Verdana", 1, 14));
        wLabel_1.setText(rb.getString("SetupMainWelcomeLabel1"));

        wLabel_2.setText(rb.getString("SetupMainWelcomeLabel2"));
        wLabel_2.setFont(new java.awt.Font("Verdana", 0, 12));

        wLabel_3.setText(rb.getString("SetupMainWelcomeLabel3"));
        wLabel_3.setFont(new java.awt.Font("Verdana", 0, 12));

        javax.swing.GroupLayout welcomePanelLayout = new javax.swing.GroupLayout(welcomePanel);
        welcomePanel.setLayout(welcomePanelLayout);
        welcomePanelLayout.setHorizontalGroup(
            welcomePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(welcomePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(welcomePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(wLabel_1, javax.swing.GroupLayout.DEFAULT_SIZE, 591, Short.MAX_VALUE)
                    .addComponent(wLabel_3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 591, Short.MAX_VALUE)
                    .addComponent(wLabel_2, javax.swing.GroupLayout.DEFAULT_SIZE, 591, Short.MAX_VALUE))
                .addContainerGap())
        );
        welcomePanelLayout.setVerticalGroup(
            welcomePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(welcomePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(wLabel_1, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(wLabel_2, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(41, 41, 41)
                .addComponent(wLabel_3, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(248, Short.MAX_VALUE))
        );

        locationPanel.setPreferredSize(new java.awt.Dimension(611, 363));

        uLabel6.setFont(new java.awt.Font("Verdana", 1, 14));
        uLabel6.setText(rb.getString("Location_1"));

        uLabel10.setFont(new java.awt.Font("Verdana", 0, 12));
        uLabel10.setText( rb.getString("Location_5") );

        uLabel11.setFont(new java.awt.Font("Verdana", 0, 12));
        uLabel11.setText(rb.getString("Location_6") );

        jTextField6.setColumns(4);

        if(!rb.getLocale().getCountry().equals("PT")){
            jTextField6.setColumns(11);
        }
        jTextField6.setFont(new java.awt.Font("Verdana", 0, 12));
        jTextField6.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField6KeyReleased(evt);
            }
        });

        jTextField7.setFont(new java.awt.Font("Verdana", 0, 12));

        uLabel12.setFont(new java.awt.Font("Verdana", 0, 12));
        uLabel12.setText( rb.getString("Location_2"));

        uLabel13.setFont(new java.awt.Font("Verdana", 0, 10));
        uLabel13.setText(rb.getString("Location_7") );

        uLabel14.setFont(new java.awt.Font("Verdana", 0, 10));
        uLabel14.setText(rb.getString("Location_8") );

        uLabel15.setFont(new java.awt.Font("Verdana", 0, 12));
        uLabel15.setText(rb.getString("Location_3") );
        uLabel15.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                uLabel15MouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                uLabel15MouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                uLabel15MouseExited(evt);
            }
        });

        jTextField5.setColumns(3);
        jTextField5.setFont(new java.awt.Font("Verdana", 0, 12));
        if(!rb.getLocale().getCountry().equals("PT")){
            jTextField5.setVisible(false);
        }
        jTextField5.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField5KeyReleased(evt);
            }
        });

        jLabel10.setText("-");
        if(!rb.getLocale().getCountry().equals("PT")){
            jLabel10.setVisible(false);
        }

        javax.swing.GroupLayout locationPanelLayout = new javax.swing.GroupLayout(locationPanel);
        locationPanel.setLayout(locationPanelLayout);
        locationPanelLayout.setHorizontalGroup(
            locationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(locationPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(locationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(uLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 484, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(locationPanelLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(locationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(uLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(uLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(locationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(locationPanelLayout.createSequentialGroup()
                                .addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, 224, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(uLabel14, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(locationPanelLayout.createSequentialGroup()
                                .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel10)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(30, 30, 30)
                                .addComponent(uLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addComponent(uLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 493, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(locationPanelLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(uLabel15, javax.swing.GroupLayout.PREFERRED_SIZE, 195, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(108, Short.MAX_VALUE))
        );
        locationPanelLayout.setVerticalGroup(
            locationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(locationPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(uLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(33, 33, 33)
                .addComponent(uLabel12)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(uLabel15)
                .addGap(63, 63, 63)
                .addGroup(locationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(locationPanelLayout.createSequentialGroup()
                        .addGap(34, 34, 34)
                        .addGroup(locationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(uLabel14, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(locationPanelLayout.createSequentialGroup()
                        .addGroup(locationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(uLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel10)
                            .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(uLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(uLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(141, Short.MAX_VALUE))
        );

        userPanel.setPreferredSize(new java.awt.Dimension(611, 363));

        uLabel1.setText(rb.getString("SetupMainUserLabel1"));
        uLabel1.setFont(new java.awt.Font("Verdana", 1, 14));

        jRadioButton1.setText(rb.getString("SetupMainUserRadioButton1"));
        jRadioButton1.setFont(new java.awt.Font("Tahoma", 0, 12));
        jRadioButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton1ActionPerformed(evt);
            }
        });

        jRadioButton2.setText(rb.getString("SetupMainUserRadioButton2"));
        jRadioButton2.setFont(new java.awt.Font("Tahoma", 0, 12));
        jRadioButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton2ActionPerformed(evt);
            }
        });

        uLabel2.setText(rb.getString("SetupMainUserLabel2"));
        uLabel2.setFont(new java.awt.Font("Verdana", 0, 12));

        uLabel3.setText(rb.getString("SetupMainUserLabel3_1"));
        uLabel3.setFont(new java.awt.Font("Verdana", 0, 12));

        uLabel4.setText(rb.getString("SetupMainUserLabel4"));
        uLabel4.setFont(new java.awt.Font("Verdana", 0, 12));

        jTextField1.setFont(new java.awt.Font("Verdana", 0, 12));

        jTextField2.setFont(new java.awt.Font("Verdana", 0, 12));

        jTextField3.setFont(new java.awt.Font("Verdana", 0, 12));

        uLabel5.setText(rb.getString("SetupMainUserLabel5"));
        uLabel5.setFont(new java.awt.Font("Verdana", 0, 12));

        jLabel5.setFont(new java.awt.Font("Verdana", 0, 12));
        jLabel5.setText(rb.getString("SetupMainUserLabel9") );

        jTextField4.setFont(new java.awt.Font("Verdana", 0, 12));

        uLabel9.setFont(new java.awt.Font("Verdana", 0, 10));
        uLabel9.setText(rb.getString("SetupMainUserLabel10"));

        javax.swing.GroupLayout userPanelLayout = new javax.swing.GroupLayout(userPanel);
        userPanel.setLayout(userPanelLayout);
        userPanelLayout.setHorizontalGroup(
            userPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(userPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(userPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(uLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 325, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(uLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 325, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(userPanelLayout.createSequentialGroup()
                        .addGap(48, 48, 48)
                        .addGroup(userPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(userPanelLayout.createSequentialGroup()
                                .addComponent(uLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 204, Short.MAX_VALUE)
                                .addGap(18, 18, 18)
                                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 260, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, userPanelLayout.createSequentialGroup()
                                .addComponent(uLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 204, Short.MAX_VALUE)
                                .addGap(18, 18, 18)
                                .addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 260, Short.MAX_VALUE))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, userPanelLayout.createSequentialGroup()
                                .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 204, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addGroup(userPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 260, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(uLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, 260, Short.MAX_VALUE)))
                            .addComponent(jRadioButton2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jRadioButton1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 206, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, userPanelLayout.createSequentialGroup()
                                .addComponent(uLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, 204, Short.MAX_VALUE)
                                .addGap(18, 18, 18)
                                .addComponent(jTextField3, javax.swing.GroupLayout.DEFAULT_SIZE, 260, Short.MAX_VALUE)))))
                .addGap(71, 71, 71))
        );
        userPanelLayout.setVerticalGroup(
            userPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(userPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(uLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(uLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jRadioButton2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jRadioButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(userPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(2, 2, 2)
                .addComponent(uLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(userPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(uLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(26, 26, 26)
                .addGroup(userPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(uLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(29, 29, 29)
                .addGroup(userPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(uLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(74, Short.MAX_VALUE))
        );

        configurationPanel.setPreferredSize(new java.awt.Dimension(611, 363));

        jLabel1.setFont(new java.awt.Font("Verdana", 1, 14));
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);

        jPanel1.setLayout(new BoxLayout(jPanel1, BoxLayout.PAGE_AXIS));
        TitledBorder tb = BorderFactory.createTitledBorder(rb.getString("SetupMainConfigurationLabel5"));
        tb.setTitleFont(new java.awt.Font("Verdana", 1,12));
        jPanel1.setBorder(tb);
        jPanel1.setFont(new java.awt.Font("Verdana", 1, 12));

        jComboBox1.setFont(new java.awt.Font("Verdana", 0, 12));
        String dontKnow = rb.getString("SetupMainConfigurationLabelCombox");
        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] {dontKnow, "56 Kb", "128 Kb", "512 Kb", "1 Mb", "2 Mb", "4 Mb", "8 Mb", "10 Mb", "100 Mb", "1 Gb","10 Gb" }));
        jComboBox1.setAutoscrolls(true);
        jComboBox1.setFocusCycleRoot(true);

        jLabel4.setFont(new java.awt.Font("Verdana", 0, 12));
        jLabel4.setText(rb.getString("SetupMainConfigurationLabel4") );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 183, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(209, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(17, Short.MAX_VALUE))
        );

        jComboBox1.setFocusable(true);

        jPanel2.setLayout(new BoxLayout(jPanel2, BoxLayout.X_AXIS));

        TitledBorder tb2 = BorderFactory.createTitledBorder(rb.getString("SetupMainConfigurationLabel10"));
        tb2.setTitleFont(new java.awt.Font("Verdana", 1,12));
        jPanel2.setBorder(tb2);
        jPanel2.setFont(new java.awt.Font("Verdana", 0, 12));

        jLabel2.setText(rb.getString("SetupMainConfigurationLabel2"));
        jLabel2.setFont(new java.awt.Font("Verdana", 0, 12));
        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);

        jLabel6.setText(rb.getString("SetupMainConfigurationLabel6"));
        jLabel6.setFont(new java.awt.Font("Verdana", 0, 12));
        jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);

        jSlider1.setMinimum(1);
        int freeSpaceGBJslider1 = (int)(MachineUtils.getFreeSpace(ConfigurationConstans.LOCAL_DIRECTORY)/SizeConstans.GByte);
        jSlider1.setMaximum(freeSpaceGBJslider1 * 10);
        jSlider1.setSnapToTicks(true);
        int offerSpaceJslider1Default = freeSpaceGBJslider1;//10%

        if(offerSpaceJslider1Default < 1)
        offerSpaceJslider1Default = 1;
        System.out.println(offerSpaceJslider1Default);
        jSlider1.setValue(offerSpaceJslider1Default);
        jSlider1.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jSlider1StateChanged(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Verdana", 0, 12));
        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        double valueGB = ( (double) jSlider1.getValue()/10);
        jLabel3.setText(df.format(valueGB)+" GB");

        jLabel7.setFont(new java.awt.Font("Verdana", 0, 12));
        jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        double freeSpaceGBLabel7 = (double) (MachineUtils.getFreeSpace(ConfigurationConstans.LOCAL_DIRECTORY)/SizeConstans.GByte);
        jLabel7.setText(df.format(freeSpaceGBLabel7)+" GB");

        jLabel9.setFont(new java.awt.Font("Verdana", 0, 12));
        jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel9.setText("0,1 GB");

        jLabel8.setFont(new java.awt.Font("Verdana", 0, 12));
        jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        double freeSpaceGBLabel8 = (double) (MachineUtils.getFreeSpace(ConfigurationConstans.LOCAL_DIRECTORY)/SizeConstans.GByte);
        jLabel8.setText(df.format(freeSpaceGBLabel8)+" GB");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jSlider1, javax.swing.GroupLayout.DEFAULT_SIZE, 562, Short.MAX_VALUE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 125, Short.MAX_VALUE)
                            .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 125, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(335, 335, 335))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 394, Short.MAX_VALUE)
                        .addComponent(jLabel8)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addGap(38, 38, 38)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 16, Short.MAX_VALUE)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addGap(18, 18, 18)
                .addComponent(jSlider1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        javax.swing.GroupLayout configurationPanelLayout = new javax.swing.GroupLayout(configurationPanel);
        configurationPanel.setLayout(configurationPanelLayout);
        configurationPanelLayout.setHorizontalGroup(
            configurationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, configurationPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(configurationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 271, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(19, Short.MAX_VALUE))
        );
        configurationPanelLayout.setVerticalGroup(
            configurationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(configurationPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(91, 91, 91))
        );

        jLabel1.setText(rb.getString("SetupMainConfigurationLabel1"));

        setupPanel.setPreferredSize(new java.awt.Dimension(611, 363));

        sLabel_1.setText(rb.getString("SetupMainSetupLabel1"));
        sLabel_1.setFont(new java.awt.Font("Verdana", 0, 12));

        sProgressBar_1.setMaximum(4);

        sLabel_2.setFont(new java.awt.Font("Verdana", 0, 12));

        javax.swing.GroupLayout setupPanelLayout = new javax.swing.GroupLayout(setupPanel);
        setupPanel.setLayout(setupPanelLayout);
        setupPanelLayout.setHorizontalGroup(
            setupPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, setupPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(setupPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(sLabel_2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 566, Short.MAX_VALUE)
                    .addComponent(sLabel_1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 566, Short.MAX_VALUE)
                    .addComponent(sProgressBar_1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 566, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(79, 79, 79))
        );
        setupPanelLayout.setVerticalGroup(
            setupPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(setupPanelLayout.createSequentialGroup()
                .addGap(17, 17, 17)
                .addComponent(sLabel_1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(60, 60, 60)
                .addComponent(sProgressBar_1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(sLabel_2, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(167, Short.MAX_VALUE))
        );

        finishPanel.setPreferredSize(new java.awt.Dimension(611, 363));

        fLabel_1.setFont(new java.awt.Font("Verdana", 1, 14));

        fLabel_2.setFont(new java.awt.Font("Verdana", 0, 12));

        fLabel_3.setFont(new java.awt.Font("Verdana", 0, 12));

        fLabel_4.setFont(new java.awt.Font("Verdana", 0, 12));
        fLabel_4.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                fLabel_4MouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                fLabel_4MouseExited(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                fLabel_4MousePressed(evt);
            }
        });

        javax.swing.GroupLayout finishPanelLayout = new javax.swing.GroupLayout(finishPanel);
        finishPanel.setLayout(finishPanelLayout);
        finishPanelLayout.setHorizontalGroup(
            finishPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(finishPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(finishPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(finishPanelLayout.createSequentialGroup()
                        .addComponent(fLabel_4, javax.swing.GroupLayout.PREFERRED_SIZE, 216, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .addGroup(finishPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(fLabel_1, javax.swing.GroupLayout.DEFAULT_SIZE, 601, Short.MAX_VALUE)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, finishPanelLayout.createSequentialGroup()
                            .addGroup(finishPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(fLabel_3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 591, Short.MAX_VALUE)
                                .addComponent(fLabel_2, javax.swing.GroupLayout.DEFAULT_SIZE, 591, Short.MAX_VALUE))
                            .addContainerGap()))))
        );
        finishPanelLayout.setVerticalGroup(
            finishPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(finishPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(fLabel_1, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(31, 31, 31)
                .addComponent(fLabel_2, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(36, 36, 36)
                .addComponent(fLabel_3, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(37, 37, 37)
                .addComponent(fLabel_4, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(171, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addComponent(userPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 611, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(mainPanelLayout.createSequentialGroup()
                    .addComponent(setupPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
            .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(mainPanelLayout.createSequentialGroup()
                    .addComponent(configurationPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addContainerGap()))
            .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                    .addComponent(finishPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
            .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(mainPanelLayout.createSequentialGroup()
                    .addComponent(welcomePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addContainerGap()))
            .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(mainPanelLayout.createSequentialGroup()
                    .addComponent(locationPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addContainerGap()))
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addComponent(userPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(mainPanelLayout.createSequentialGroup()
                    .addComponent(setupPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
            .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(mainPanelLayout.createSequentialGroup()
                    .addComponent(configurationPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 363, Short.MAX_VALUE)
                    .addContainerGap()))
            .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                    .addComponent(finishPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
            .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(mainPanelLayout.createSequentialGroup()
                    .addComponent(welcomePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addContainerGap()))
            .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(mainPanelLayout.createSequentialGroup()
                    .addComponent(locationPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addContainerGap()))
        );

        jRadioButton1.setSelected(true);
        jRadioButton1.setSelected(true);

        button_next.setText(rb.getString("button_next"));
        button_next.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                button_nextActionPerformed(evt);
            }
        });

        button_back.setText(rb.getString("button_back"));
        button_back.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                button_backActionPerformed(evt);
            }
        });

        button_cancel.setText(rb.getString("button_cancel"));
        button_cancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                button_cancelActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(mainPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 621, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(22, 22, 22))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(separator, javax.swing.GroupLayout.DEFAULT_SIZE, 623, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(button_back, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(button_next, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(32, 32, 32)
                                .addComponent(button_cancel, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(mainPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 374, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(separator, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(button_back, javax.swing.GroupLayout.DEFAULT_SIZE, 22, Short.MAX_VALUE)
                    .addComponent(button_cancel, javax.swing.GroupLayout.DEFAULT_SIZE, 22, Short.MAX_VALUE)
                    .addComponent(button_next, javax.swing.GroupLayout.DEFAULT_SIZE, 22, Short.MAX_VALUE))
                .addContainerGap())
        );

        button_back.setEnabled(true);

        pack();
    }// </editor-fold>//GEN-END:initComponents


    private void initAttributes(ResourceBundle rb,Logger logger){
        this.rb = rb;
        this.logger = logger;
		this.df = new DecimalFormat("0.0");
    }


	private void button_cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_button_cancelActionPerformed
        if( !setupPanel.isVisible() && !configurationPanel.isVisible() && !finishPanel.isVisible()){
            showWarningDialog();
        }
        else{
            

            showFinishPanelProblems();
        }
	}//GEN-LAST:event_button_cancelActionPerformed


	private void button_nextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_button_nextActionPerformed

		if (welcomePanel.isVisible()) {     
            showUserPanel();
		} else if(userPanel.isVisible()){
			if(validetInput()){
                showLocationPanel();
			}                                
		} else if(locationPanel.isVisible()){

            showSetupPanel();

            String zipCode = getZipCode();

			identifierRetriver = new IdentifierRetriver(jTextField1.getText(),jTextField2.getText(),
                    jTextField4.getText(),jRadioButton1.isSelected(),zipCode, jTextField7.getText(),
                    setupPanel, configurationPanel, sLabel_1, sProgressBar_1, sLabel_2,button_back,
                    button_next,button_cancel, rb, logger);

			identifierRetriver.execute();

		} else if(setupPanel.isVisible()){


			try {
				result = identifierRetriver.get();
                System.out.println(result);
			} catch (InterruptedException e) {
                logger.log(Level.SEVERE,"Problems("+e.getMessage()+"...exit");
                System.exit(1);
            } catch (ExecutionException e) {
                logger.log(Level.SEVERE,"Problems("+e.getMessage()+"...exit");
                System.exit(1);
            }


			if(result){
                showConfigurationPanel();
			} else{

                button_next.setText(rb.getString("button_finish"));
                fLabel_1.setText(rb.getString("SetupMain_Finish_Problems_label_1"));
                fLabel_2.setText(rb.getString("SetupMain_Finish_Problems_label_2"));

                showFinishPanelProblems();
			}                  

		} else if(configurationPanel.isVisible()){

            try {
                Configuration configuration = createConfiguration();
				configuration.save(ConfigurationConstans.CONFIGURATION_FILENAME);
			} catch (IOException e) {
                logger.log(Level.WARNING,"Can not create configuration file. Problem["+e.getMessage()+"]");
            }

			button_next.setText(rb.getString("button_finish"));
			fLabel_1.setText(rb.getString("SetupMain_Finish_label_1"));
			fLabel_2.setText(rb.getString("SetupMain_Finish_label_2"));
			fLabel_3.setText(rb.getString("SetupMain_Finish_label_3"));
            fLabel_4.setText(rb.getString("SetupMain_Finish_label_4"));

            showFinishPanel();

		}else if(finishPanel.isVisible()){

            if(MachineUtils.existsFile(ConfigurationConstans.LOCAL_DIRECTORY,
                    ConfigurationConstans.IDENTIFIER_FILENAME)){

				try {

                    launchRarc();

                    setVisible(false);               
                    
                    System.exit(0);

				} catch (IOException e){
                    logger.log(Level.SEVERE,"It does not exist rARC file. rARC is not going to work!!!");
                    System.exit(1);
                }
			}else{
                logger.log(Level.SEVERE,"It does not exist Identifier file. rARC is not going to work!!!");
                System.exit(1);
            }
		}    
	}//GEN-LAST:event_button_nextActionPerformed


	private void button_backActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_button_backActionPerformed
        if(userPanel.isVisible()){
            showWelcomePanel();
		} else if(finishPanel.isVisible()){
			button_next.setText(rb.getString("button_next"));
            showConfigurationPanel();
		}else if(setupPanel.isVisible() || locationPanel.isVisible()){
            showUserPanel();
        }
	}//GEN-LAST:event_button_backActionPerformed


	private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
		if(welcomePanel.isVisible() || userPanel.isVisible())
            showWarningDialog();
	}//GEN-LAST:event_formWindowClosing


	private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton1ActionPerformed
		showAndHide(evt);
	}//GEN-LAST:event_jRadioButton1ActionPerformed


	private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton2ActionPerformed
		showAndHide(evt);
	}//GEN-LAST:event_jRadioButton2ActionPerformed


	private void jSlider1StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jSlider1StateChanged
        double valueGB = ( (double) jSlider1.getValue()/10);
        jLabel3.setText(df.format(valueGB)+" GB");
	}//GEN-LAST:event_jSlider1StateChanged


    private void uLabel15MouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_uLabel15MouseEntered
        Cursor normalCursor = new Cursor(Cursor.HAND_CURSOR);
        setCursor(normalCursor);
    }//GEN-LAST:event_uLabel15MouseEntered


    private void uLabel15MouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_uLabel15MouseExited
        Cursor normalCursor = new Cursor(Cursor.DEFAULT_CURSOR);
        setCursor(normalCursor);
    }//GEN-LAST:event_uLabel15MouseExited


    private void uLabel15MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_uLabel15MouseClicked
        openBrowser();
    }//GEN-LAST:event_uLabel15MouseClicked


    private void jTextField6KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField6KeyReleased

        final int MAX_SIZE = 4;
        String zipcode = jTextField6.getText();

        if(rb.getLocale().getCountry().equals("PT")){
            
            if(zipcode.length() > MAX_SIZE)
                jTextField6.setText(zipcode.substring(0,MAX_SIZE));

            try{
                
                Integer.parseInt(zipcode);

                if(zipcode.length() == MAX_SIZE)
                    jTextField5.requestFocus();
                
            } catch(NumberFormatException e){
                if(zipcode.length()!=0)
                    jTextField6.setText(zipcode.substring(0, zipcode.length()-1));
            }
        }       
    }//GEN-LAST:event_jTextField6KeyReleased

    
    private void jTextField5KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField5KeyReleased

        final int MAX_SIZE = 3;
        String subZipcode = jTextField5.getText();


        if(subZipcode.length() > MAX_SIZE){
            jTextField5.setText(subZipcode.substring(0,MAX_SIZE));
        }

        try{
            Integer.parseInt(subZipcode);
        } catch(NumberFormatException e){
            if(subZipcode.length()!=0)
                jTextField5.setText(subZipcode.substring(0, subZipcode.length()-1));
        }        
    }//GEN-LAST:event_jTextField5KeyReleased

    private void fLabel_4MouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_fLabel_4MouseEntered
        Cursor normalCursor = new Cursor(Cursor.HAND_CURSOR);
        setCursor(normalCursor);
    }//GEN-LAST:event_fLabel_4MouseEntered

    private void fLabel_4MouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_fLabel_4MouseExited
        Cursor normalCursor = new Cursor(Cursor.DEFAULT_CURSOR);
        setCursor(normalCursor);
    }//GEN-LAST:event_fLabel_4MouseExited

    private void fLabel_4MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_fLabel_4MousePressed
        openMail();
    }//GEN-LAST:event_fLabel_4MousePressed
    

    private void openBrowser() {

        String language = rb.getLocale().getLanguage();
        String url;

        if(language.equals("en"))
            url = "http://arquivo-web.fccn.pt/about-the-archive/how-does-it-work/rarc/location-of-backup-files";
        else
            url = "http://arquivo-web.fccn.pt/sobre-o-arquivo/funcionamento/localizacao-das-copias-de-seguranca";
        
        try {
            MachineUtils.openBrowser(url);
        } catch (URISyntaxException ex) {
            Logger.getLogger(SetupFrame.class.getName()).log(Level.WARNING,null,ex);
        } catch (IOException ex) {
            Logger.getLogger(SetupFrame.class.getName()).log(Level.WARNING,null,ex);
        }        
    }

    private void openMail() {
        try {
            MachineUtils.openEmail(null,rb.getString("SetupMain_Finish_email_subject"),
                    rb.getString("SetupMain_Finish_email_message"));
        } catch (URISyntaxException ex) {
            Logger.getLogger(SetupFrame.class.getName()).log(Level.WARNING,null,ex);
        } catch (IOException ex) {
            Logger.getLogger(SetupFrame.class.getName()).log(Level.WARNING,null,ex);
        }
    }

    
	private void showAndHide(java.awt.event.ActionEvent evt) {

		if(evt.getSource()== jRadioButton1){

			jRadioButton2.setSelected(false);
			uLabel3.setText(rb.getString("SetupMainUserLabel3_1"));
			uLabel4.setVisible(true);
			jTextField3.setVisible(true);
            jLabel5.setVisible(true);
            jTextField4.setVisible(true);
            uLabel9.setVisible(true);

			jRadioButton1.setSelected(true);

		} else if(evt.getSource()== jRadioButton2){

			jRadioButton1.setSelected(false);

			uLabel3.setText(rb.getString("SetupMainUserLabel3"));
			uLabel4.setVisible(false);
			jTextField3.setVisible(false);
            jLabel5.setVisible(false);
            jTextField4.setVisible(false);
            uLabel9.setVisible(false);
            
			jRadioButton2.setSelected(true);
		}
	}


    private boolean validetInput() {


        int MAX_LENGTH_PASSWORD = 30;

        

		if(jTextField4.getText().isEmpty() &&
           jRadioButton1.isSelected())
        {
			showErrorMessage(rb.getString("SpecifyName"));
			return false;
		}


		if(jTextField1.getText().isEmpty())
        {
			showErrorMessage(rb.getString("SpecifyEmail"));
			return false;
		}

        if(!EmailUtils.verification(jTextField1.getText()))
        {
			showErrorMessage(rb.getString("InvalidEmail"));
			return false;
		}


		if( jTextField2.getText().isEmpty())
        {
			showErrorMessage(rb.getString("WrongPassword"));
            return false;
		}        
        else if(jTextField2.getText().length() > MAX_LENGTH_PASSWORD)
        {
            showErrorMessage(rb.getString("MaxPassword"));
            return false;
        }

        if(!jTextField2.getText().equals(jTextField3.getText()) &&
           jRadioButton1.isSelected())
        {
			showErrorMessage(rb.getString("MatchPassword"));
			return false;
		}

		return true;
	}


    private void showWarningDialog() {

		Object[] options = {rb.getString("options_yes"),rb.getString("options_no")};

        if(JOptionPane.showOptionDialog(this,rb.getString("SetupWarnningLabel"),
					rb.getString("MessageTitleSetup"),JOptionPane.YES_NO_OPTION,
					JOptionPane.WARNING_MESSAGE, null,options, options[0])== JOptionPane.YES_OPTION)
				System.exit(1);
	}

    
	private void showErrorMessage(String errorMessage){
		JOptionPane.showMessageDialog(this,errorMessage, rb.getString("MessageTitleSetup"),
                JOptionPane.ERROR_MESSAGE);
	}


    private void setVisiblePanels(boolean setWelcomePanel,boolean setUserPanel,
            boolean setLocationPanel,boolean setSetupPanel,
            boolean setConfigurationPanel, boolean setFinishPanel){
		welcomePanel.setVisible(setWelcomePanel);
		userPanel.setVisible(setUserPanel);
        locationPanel.setVisible(setLocationPanel);
		setupPanel.setVisible(setSetupPanel);
		configurationPanel.setVisible(setConfigurationPanel);
		finishPanel.setVisible(setFinishPanel);
	}


	private void setVisibleButtons(boolean nextButton, boolean backButton,
            boolean cancelButton){
		button_next.setVisible(nextButton);
		button_back.setVisible(backButton);
		button_cancel.setVisible(cancelButton);
	}


	private void setEnableButtons(boolean nextButton,boolean backButton,
            boolean cancelButton){
		button_next.setEnabled(nextButton);
		button_back.setEnabled(backButton);
		button_cancel.setEnabled(cancelButton);
	}

    
    private void showWelcomePanel(){
        setVisiblePanels(true,false,false,false,false,false);
		setVisibleButtons(true,false,true);
    }

    
    private void showUserPanel(){
        setEnableButtons(true,true,true);
		setVisibleButtons(true,true,true);
		setVisiblePanels(false,true,false,false,false,false);
    }


    private void showLocationPanel(){
        setEnableButtons(true,true,true);
        setVisibleButtons(true, true, true);
        setVisiblePanels(false,false,true,false,false,false);
    }


    private void showSetupPanel(){
        setEnableButtons(false,false,false);
        setVisibleButtons(true, true, true);
        setVisiblePanels(false,false,false,true,false,false);
    }


    private void showConfigurationPanel(){

        button_next.setText(rb.getString("button_finish"));
        fLabel_1.setText(rb.getString("SetupMain_Finish_Problems_label_1"));
        fLabel_2.setText(rb.getString("SetupMain_Finish_Problems_label_2"));

        setEnableButtons(true,false,false);
		setVisibleButtons(true, true, true);
		setVisiblePanels(false,false,false,false,true,false);
    }


    private void showFinishPanel(){
        setEnableButtons(true,true,false);
		setVisibleButtons(true,true,true);
		setVisiblePanels(false,false,false,false,false,true);
    }


    private void showFinishPanelProblems() {
        setEnableButtons(true,false,false);
		setVisibleButtons(true, true, true);
		setVisiblePanels(false,false,false,false,false,true);
	}


    private Configuration createConfiguration(){

        Configuration configuration = new Configuration();

        double offerSpaceGB =( (double) jSlider1.getValue()/10);
        long offerSpaceBytes = (long) ((offerSpaceGB) * SizeConstans.GByte);
        configuration.setOfferSpace(offerSpaceBytes);

        int index = jComboBox1.getSelectedIndex();
        BandwidthConnection bc = null;

        if(index > 0)
            bc = BandwidthConnection.values()[index-1];
        else
            bc = BandwidthConnection.KB_56;

        configuration.setBandwidth(bc);

        return configuration;
    }


    private String getZipCode() {
        String zipCode = null;

        if(rb.getLocale().getCountry().equals("PT"))
            zipCode = jTextField6.getText()+" "+jTextField5.getText();
        else
            zipCode = jTextField6.getText();

        return zipCode;
    }

    
    private void launchRarc()
            throws IOException{

        String NameRarcApplication = "rArc";

        Runtime.getRuntime().exec(NameRarcApplication,null,new File(ConfigurationConstans.LOCAL_DIRECTORY));
    }

    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton button_back;
    private javax.swing.JButton button_cancel;
    private javax.swing.JButton button_next;
    private javax.swing.JPanel configurationPanel;
    private javax.swing.JLabel fLabel_1;
    private javax.swing.JLabel fLabel_2;
    private javax.swing.JLabel fLabel_3;
    private javax.swing.JLabel fLabel_4;
    private javax.swing.JPanel finishPanel;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JSlider jSlider1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JTextField jTextField6;
    private javax.swing.JTextField jTextField7;
    private javax.swing.JPanel locationPanel;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JLabel sLabel_1;
    private javax.swing.JLabel sLabel_2;
    private javax.swing.JProgressBar sProgressBar_1;
    private javax.swing.JSeparator separator;
    private javax.swing.JPanel setupPanel;
    private javax.swing.JLabel uLabel1;
    private javax.swing.JLabel uLabel10;
    private javax.swing.JLabel uLabel11;
    private javax.swing.JLabel uLabel12;
    private javax.swing.JLabel uLabel13;
    private javax.swing.JLabel uLabel14;
    private javax.swing.JLabel uLabel15;
    private javax.swing.JLabel uLabel2;
    private javax.swing.JLabel uLabel3;
    private javax.swing.JLabel uLabel4;
    private javax.swing.JLabel uLabel5;
    private javax.swing.JLabel uLabel6;
    private javax.swing.JLabel uLabel9;
    private javax.swing.JPanel userPanel;
    private javax.swing.JLabel wLabel_1;
    private javax.swing.JLabel wLabel_2;
    private javax.swing.JLabel wLabel_3;
    private javax.swing.JPanel welcomePanel;
    // End of variables declaration//GEN-END:variables
  
}



